package com.example.demo.controller;

import com.alibaba.fastjson.JSONObject;
import com.example.demo.mapper.ScoreMapper;
import com.example.demo.entity.Message;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@Controller
public class DeleteScoreController {
   @Autowired
   private ScoreMapper sm;
@RequestMapping("/deletescore")
    public void deleteScore(HttpServletRequest request, HttpServletResponse response) throws IOException {
    int flag=Integer.valueOf(request.getParameter("flag"));
    int n=sm.deleteScore(flag+1);
    if(n>0){
        try {
            response.getWriter().write(JSONObject.toJSONString(Message.success("Delete score success")));
        } catch (IOException e) {
            response.getWriter().write(JSONObject.toJSONString(Message.failure(e.getMessage())));
        }
    }
}
}
